package Database;

import java.lang.Comparable;
import java.util.Comparator;

public class Document implements Comparable<Document>, Comparator<Document>
{    
    private String url = null;
    private String title = null;
 
    public Document()
    {
    }
    
    public Document(String url, String title) 
    {
        this.url = url;
        this.title = title;
    }
    
    public String getUrl()
    {
        return url;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public void setUrl(String url)
    {
        this.url = url;
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public String toString()
    {
        return getTitle() + " << " + getUrl() + " >>";
    }
    
    public int compareTo(Document o)
    {
        if(this.title.compareTo(o.getTitle()) == 0)
            return this.url.compareTo(o.getUrl());
        else
            return this.title.compareTo(o.getTitle());
    }

    public int compare(Document o1, Document o2)
    {
        return o1.compareTo(o2);
    }
    
    public boolean equals(Object obj)
    {
        if(!(obj instanceof Document)) return false;
        return this.compareTo((Document)obj) == 0;
    }
}
